package com.gf.user.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.gf.base.type.Activity;
import com.gf.base.type.TicketType;
import com.gf.user.model.Ticket;

public class TicketMapper implements RowMapper<Ticket>{

	private final static String COLUME_ID = "id";
	private final static String COLUME_USERID = "userId";
	private final static String COLUME_UUID= "uuid";
	private final static String COLUME_CREATETIME = "createtime";
	private final static String COLUME_ACTIVITY = "activity";
	private final static String COLUME_TICKETTYPE="ticketType";
	

	private final static TicketMapper MAPPER = new TicketMapper();

	public final static TicketMapper getMapper() {
		return MAPPER;
	}
	
	@Override
	public Ticket mapRow(ResultSet set, int row) throws SQLException {
		Ticket ticket = new Ticket();
		
		ticket.setId(set.getLong(COLUME_ID));
		ticket.setUserId(set.getLong(COLUME_USERID));
		ticket.setUuid(set.getString(COLUME_UUID));
		ticket.setCreatetime(set.getTimestamp(COLUME_CREATETIME));
		ticket.setActivity(Activity.valueOf(set.getString(COLUME_ACTIVITY)));
		ticket.setTicketType(TicketType.valueOf(set.getString(COLUME_TICKETTYPE)));
		
		return ticket;
	}

}
